package com.ruoyi.shop.modules.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.shop.modules.domain.UserGroup;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@DataSource(value = DataSourceType.SLAVE)
public interface CKMapper extends BaseMapper<UserGroup> {

    @Insert("${sql}")
        //${} #{} => #{} 加引号 ，${} 不加引号
    void insertsql(@Param("sql") String sql);


    @Select("select arrayJoin(bitmapToArray(us)) us from user_group where user_group_id=#{id}")
    List<String> getSelectUsergroupById(@Param("id") String id);


    @Select("${sql}")
    Long getSelectUsergroupByIdCount(@Param("sql") String sql);


    @Delete("alter table user_group delete where user_group_id=#{id}")
    Long DeleteUsergroupById(@Param("id") String id);

    @Select("SELECT COUNT(*)" +
            "FROM (" +
            "    SELECT arrayJoin(bitmapToArray(us)) as us" +
            "    FROM user_tag_value_string" +
            "    WHERE tag_value = #{tagValue} AND dt = #{dt}" +
            ")")
    Long selectTagCount(@Param("tagValue")String tagValue ,@Param("dt") String dt);

    List<String> selectUsByDt(String tagValue, String dt);
}
